package grabNtrans;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Pattern;

import com.google.api.translate.Language;
import com.google.api.translate.Translate;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;

public class TransSub {
	
	final static String endPoint = "http://api.microsofttranslator.com/V2/Soap.svc";
	Service service;
	String translate() throws Exception {

		Call     call    = (Call) service.createCall();
		  
		        call.setTargetEndpointAddress( new java.net.URL(endPoint) );
		       call.setOperationName(new QName("http://soapinterop.org/", "echoString"));
		 
		     String ret = (String) call.invoke( new Object[] { "Hello!" } );
		System.out.println(ret);
		return ret;
	}

	void exec(String dir, Language from, Language to) throws Exception {
		// Open the file that is the first
		// command line parameter
		FileInputStream fstream = new FileInputStream(dir);
		service = new Service();
		// Get the object of DataInputStream
		DataInputStream in = new DataInputStream(fstream);
		BufferedReader br = new BufferedReader(new InputStreamReader(in));
		String strLine;
		// Read File Line By Line

		Pattern p = Pattern.compile("[0-9]*");

		while ((strLine = br.readLine()) != null) {
			// Print the content on the console
			if (strLine.contains("-->") || "".equals(strLine)
					|| p.matcher(strLine).matches())
				continue;
			System.out.println(translate());
		}
		// Close the input stream
		in.close();
	}

}